extends Talent
var utils = globalData.infoDs["g_AneHekUtils"]

func init():
	name = "战争墓钟[通用]"

func _connect():
	sys.main.connect("onBattleReady",self,"run")
	sys.main.connect("onBattleEnd",self,"run2")

func run():
	var chas = utils.getAllChas(2)
	chas.sort_custom(self,"sort")
	var v = [Vector2(7,2),Vector2(7,3)]
	var flag = 0
	var cells
	for i in v:
		if sys.main.matCha(i) == null:
			flag = 1
			cells = i
			break
	if !flag:
		v = utils.cellsRight
		for i in v:
			if sys.main.matCha(i) == null:
				flag = 1
				cells = i
				break
	if !flag:return
	var idd = "cex___Hide_clock"
	if chas[0].lv == 3:
		idd += "2"
	if chas[0].lv == 4:
		idd += "3"
	var cha = sys.main.newChara(idd,1)
	sys.main.map.add_child(cha)
	sys.main.setMatCha(cells, cha)
	cha.attInfo.maxHp = chas[0].att.maxHp * 0.5
	if chas[0].lv == 3:
		cha.attInfo.def = 33
		cha.attInfo.mgiDef = 33
	if chas[0].lv == 4:
		cha.attInfo.def = 100
		cha.attInfo.mgiDef = 100
	cha.upAtt()

func run2():
	var chas = utils.getAllChas(2)
	for i in chas:
		if i.id.find("clock") != -1:
			i.delself()

func sort(a,b):
	if a.lv != b.lv:
		return a.lv > b.lv
	return a.att.maxHp > b.att.maxHp

func get_info():
	return  "敌方进场时在敌方空白位置[优先中间]召唤一个墓钟[血量为等级最高的血量最多的英雄的一半血]，开始战斗时嘲讽所有敌人。\n此天赋不需要升级"

